package com.key.puzzlemodel.util

import android.app.Activity
import android.content.Context
import android.os.Build
import android.os.VibrationEffect
import android.os.Vibrator
import java.lang.Exception

/**
 *
 * @功能描述:
 * @创建时间:     2022/1/7
 * @创建者:       阳
 * @修改时间:     2022/1/7
 * @修改者:       阳
 */
object VibratorUtil {

    /**
     * 震动
     *
     * @param context
     */
    fun onVibrator(context: Context?) {
        if (null != context) {
            try {
                val vibrator = context.getSystemService(Activity.VIBRATOR_SERVICE) as Vibrator
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                    vibrator.vibrate(
                        VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE)
                    )
                } else {
                    vibrator.vibrate(50)
                }
            } catch (e: Exception) {
            }
        }
    }
}